package com.ruoyi.animalManagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.animalManagement.domain.LmisAnimal;
import com.ruoyi.animalManagement.service.ILmisAnimalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 动物档案管理Controller
 * 
 * @author wj
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/animalManagement/animal")
public class LmisAnimalController extends BaseController
{
    @Autowired
    private ILmisAnimalService lmisAnimalService;

    /**
     * 查询动物档案管理列表
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:list')")
    @GetMapping("/list")
    public TableDataInfo list(LmisAnimal lmisAnimal)
    {
        startPage();
        List<LmisAnimal> list = lmisAnimalService.selectLmisAnimalList(lmisAnimal);
        return getDataTable(list);
    }

    /**
     * 导出动物档案管理列表
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:export')")
    @Log(title = "动物档案管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LmisAnimal lmisAnimal)
    {
        List<LmisAnimal> list = lmisAnimalService.selectLmisAnimalList(lmisAnimal);
        ExcelUtil<LmisAnimal> util = new ExcelUtil<LmisAnimal>(LmisAnimal.class);
        util.exportExcel(response, list, "动物档案管理数据");
    }

    /**
     * 获取动物档案管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:query')")
    @GetMapping(value = "/{animalId}")
    public AjaxResult getInfo(@PathVariable("animalId") Long animalId)
    {
        return success(lmisAnimalService.selectLmisAnimalByAnimalId(animalId));
    }

    /**
     * 新增动物档案管理
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:add')")
    @Log(title = "动物档案管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LmisAnimal lmisAnimal)
    {
        return toAjax(lmisAnimalService.insertLmisAnimal(lmisAnimal));
    }

    /**
     * 修改动物档案管理
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:edit')")
    @Log(title = "动物档案管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LmisAnimal lmisAnimal)
    {
        return toAjax(lmisAnimalService.updateLmisAnimal(lmisAnimal));
    }

    /**
     * 删除动物档案管理
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:remove')")
    @Log(title = "动物档案管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{animalIds}")
    public AjaxResult remove(@PathVariable Long[] animalIds)
    {
        return toAjax(lmisAnimalService.deleteLmisAnimalByAnimalIds(animalIds));
    }

    /**
     * 动物淘汰：将动物状态设置为2（淘汰）
     */
    @PreAuthorize("@ss.hasPermi('animalManagement:animal:edit')")
    @Log(title = "动物档案管理", businessType = BusinessType.UPDATE)
    @PutMapping("/eliminate/{animalId}")
    public AjaxResult eliminate(@PathVariable("animalId") Long animalId)
    {
        LmisAnimal animal = lmisAnimalService.selectLmisAnimalByAnimalId(animalId);
        if (animal == null)
        {
            return AjaxResult.error("动物不存在");
        }
        animal.setAnimalStatus("2");
        return toAjax(lmisAnimalService.updateLmisAnimal(animal));
    }
}
